package com.example.wangzh.developkit.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;

import com.example.wangzh.developkit.R;
import com.example.wangzh.developkit.model.Evaluate;

import java.util.List;

/**
 * @author fyales
 * @since 8/26/15.
 */
public class EvaluateAdapter extends BaseAdapter {

	private Context mContext;
	private List<Evaluate> evaluates;

	public EvaluateAdapter(Context mContext, List<Evaluate> evaluates) {
		this.mContext = mContext;
		this.evaluates = evaluates;
	}

	@Override
	public int getCount() {
		return evaluates.size();
	}

	@Override
	public String getItem(int position) {
		return evaluates.get(position).getEvalDetail();
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(R.layout.tag_item_tag_view, null);
			holder = new ViewHolder( );
			holder.tagBtn = (Button) convertView.findViewById(R.id.tag_btn);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag( );
		}
		final String text = evaluates.get(position).getEvalDetail();
		holder.tagBtn.setText(text);
		holder.tagBtn.setSelected(evaluates.get(position).isSelected());
		return convertView;
	}

	static class ViewHolder {
		Button tagBtn;
	}
}
